package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.api.dto.GoodsClassifyDTO;
import com.qinggeng.project.system.domain.GoodsClassify;
import com.qinggeng.project.system.service.IGoodsClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类信息Controller
 *
 * @author qinggeng
 * @date 2020-05-27
 */
@RestController
@RequestMapping("${systemPath}/classify")
public class GoodsClassifyController extends BaseController {
    @Autowired
    private IGoodsClassifyService goodsClassifyService;

    /**
     * 查询商品分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:classify:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsClassify goodsClassify) {
        List<GoodsClassify> list = goodsClassifyService.selectGoodsClassifyList(goodsClassify);
        return getDataTable(list);
    }

    /**
     * 导出商品分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:classify:export')")
    @Log(title = "商品分类信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsClassify goodsClassify) {
        List<GoodsClassify> list = goodsClassifyService.selectGoodsClassifyList(goodsClassify);
        ExcelUtil<GoodsClassify> util = new ExcelUtil<GoodsClassify>(GoodsClassify.class);
        return util.exportExcel(list, "classify");
    }

    /**
     * 获取商品分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:classify:query')")
    @GetMapping(value = "/{classifyId}")
    public AjaxResult getInfo(@PathVariable("classifyId") Long classifyId) {
        return AjaxResult.success(goodsClassifyService.selectGoodsClassifyById(classifyId));
    }

    /**
     * 新增商品分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classify:add')")
    @Log(title = "商品分类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsClassifyDTO dto) {
        return toAjax(goodsClassifyService.insertGoodsClassify(dto));
    }

    /**
     * 修改商品分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classify:edit')")
    @Log(title = "商品分类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsClassifyDTO goodsClassify) {
        return toAjax(goodsClassifyService.updateGoodsClassify(goodsClassify));
    }

    /**
     * 删除商品分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classify:remove')")
    @Log(title = "商品分类信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classifyIds}")
    public AjaxResult remove(@PathVariable Long[] classifyIds) {
        //进行逻辑删除 批量修改为已删除
        return toAjax(goodsClassifyService.deleteGoodsClassifyByIds(classifyIds));
    }

    /**
     * 获取商品分类 可筛选
     */
    @GetMapping("/getGoodsClassify")
    @ResponseBody
    public AjaxResult getGoodsClassifyList() {
        GoodsClassify classify = new GoodsClassify();
        classify.setVisible("0");
        classify.setIsActivity("20");
        List<GoodsClassify> goodsClassifies = goodsClassifyService.selectGoodsClassifyList(classify);
        return AjaxResult.success(goodsClassifies);
    }

    /**
     * 获取商品分类 可筛选
     */
    @GetMapping("/getGoodsClassifyListForOne")
    @ResponseBody
    public AjaxResult getGoodsClassifyListForOne() {
        GoodsClassify classify = new GoodsClassify();
        classify.setVisible("0");
        classify.setRank(1);
        classify.setIsActivity("20");
        List<GoodsClassify> goodsClassifies = goodsClassifyService.selectGoodsClassifyList(classify);
        return AjaxResult.success(goodsClassifies);
    }

    /**
     * 获取商品分类 可筛选
     */
    @GetMapping("/getClassifyListForOne")
    @ResponseBody
    public AjaxResult getClassifyListForOne() {
        GoodsClassify classify = new GoodsClassify();
        classify.setVisible("0");
        classify.setRank(1);
        List<GoodsClassify> goodsClassifies = goodsClassifyService.selectGoodsClassifyList(classify);
        return AjaxResult.success(goodsClassifies);
    }

    /**
     * 删除綁定一級商品商品分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classify:remove')")
    @GetMapping("/delGoodsLowerClassifyById")
    public AjaxResult delGoodsLowerClassifyById(Long id) {
        //进行逻辑删除
        return toAjax(goodsClassifyService.delGoodsLowerClassifyById(id));
    }


}
